<?php
namespace App\Library\wxOpen;

class WeChatApi
{
    // 微信相关  https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/cloudbase/cloudbase.html
    const WE_CHAT_API_URL = 'https://api.weixin.qq.com'; // 微信API地址
    const WE_CHAT_MP_API_URL = 'https://mp.weixin.qq.com'; // 微信公众号地址
    const WE_CHAT_OPEN_API_URL = 'https://open.weixin.qq.com'; // 微信公众号授权地址
    static $weChat_conf = [
        'component_login_page' => self::WE_CHAT_MP_API_URL.'/cgi-bin/componentloginpage', // 公众平台授权地址
        'user_info' => self::WE_CHAT_API_URL.'/sns/userinfo', // openid获取用户信息
        'get_access_token' => self::WE_CHAT_API_URL.'/sns/oauth2/access_token', // 获取access_token

        'connect_authorize' => self::WE_CHAT_OPEN_API_URL.'/connect/oauth2/authorize', // 微信公众号网页授权地址
        'qr_connect' => self::WE_CHAT_OPEN_API_URL.'/connect/qrconnect', // 微信开放平台网页授权登录页面地址

        'get_wxa_code_unLimit' => self::WE_CHAT_API_URL.'/wxa/getwxacodeunlimit', // 获取二维码
        'template_send' => self::WE_CHAT_API_URL.'/cgi-bin/message/wxopen/template/send', // 发送微信模板消息接口
        'get_token' => self::WE_CHAT_API_URL.'/cgi-bin/token', // 小程序调用token
        'custom_send' => self::WE_CHAT_API_URL.'/cgi-bin/message/custom/send', // 发送客服消息
        "invoke_cloud_function" => self::WE_CHAT_API_URL."/tcb/invokecloudfunction", // 触发小程序云函数
        "upload_file" => self::WE_CHAT_API_URL."/tcb/uploadfile", // 小程序云函数 文件上传链接
        "batch_download_file" => self::WE_CHAT_API_URL."/tcb/batchdownloadfile", // 小程序云函数 文件下载链接
        "batch_delete_file" => self::WE_CHAT_API_URL."/tcb/batchdeletefile", // 小程序云函数 文件下载链接
        "list_functions" => self::WE_CHAT_API_URL."/tcb/listfunctions", // 获取云函数列表

        'api_component_token' => self::WE_CHAT_API_URL.'/cgi-bin/component/api_component_token', // 获取令牌
        'api_create_preAuthCode' => self::WE_CHAT_API_URL.'/cgi-bin/component/api_create_preauthcode', // 获取预授权码
        'api_query_auth' => self::WE_CHAT_API_URL.'/cgi-bin/component/api_query_auth', // 授权码获取授权信息
        'api_authorizer_token' => self::WE_CHAT_API_URL.'/cgi-bin/component/api_authorizer_token', // 获取/刷新接口调用令牌token
        'api_get_authorizer_info' => self::WE_CHAT_API_URL.'/cgi-bin/component/api_get_authorizer_info', // 获取授权方的帐号基本信息
        'api_get_authorizer_list' => self::WE_CHAT_API_URL.'/cgi-bin/component/api_get_authorizer_list', // 拉取当前所有已授权的帐号基本信息
        'modify_domain' => self::WE_CHAT_API_URL.'/wxa/modify_domain', // 设置服务器域名
        'set_web_view_domain' => self::WE_CHAT_API_URL.'/wxa/setwebviewdomain', // 设置业务域名
        'get_category' => self::WE_CHAT_API_URL.'/cgi-bin/wxopen/getcategory', // 获取已设置的所有类目
        'get_all_categories' => self::WE_CHAT_API_URL.'/cgi-bin/wxopen/getallcategories', // 获取可设置的所有类目
        'get_template_list' => self::WE_CHAT_API_URL.'/wxa/gettemplatelist', // 获取代码模板列表
        'commit' => self::WE_CHAT_API_URL.'/wxa/commit', // 提交小程序代码
        'get_page' => self::WE_CHAT_API_URL.'/wxa/get_page', // 获取小程序页面地址
        'get_qrCode' => self::WE_CHAT_API_URL.'/wxa/get_qrcode', // 获取的体验版二维码
        'submit_audit' => self::WE_CHAT_API_URL.'/wxa/submit_audit', // 提交审核
        'get_auditStatus' => self::WE_CHAT_API_URL.'/wxa/get_auditstatus', // 查询指定发布审核单的审核状态
        'get_latest_auditStatus' => self::WE_CHAT_API_URL.'/wxa/get_latest_auditstatus', // 查询最新一次提交的审核状态
        'release' => self::WE_CHAT_API_URL.'/wxa/release', // 发布已通过审核的小程序
        'undo_code_audit' => self::WE_CHAT_API_URL.'/wxa/undocodeaudit', // 小程序审核撤回
        'get_account_basic_info' => self::WE_CHAT_API_URL.'/cgi-bin/account/getaccountbasicinfo', //
        "fast_register_weApp" => self::WE_CHAT_API_URL."/cgi-bin/component/fastregisterweapp", // 快速创建小程序

        'create_cloud_user' => self::WE_CHAT_API_URL.'/tcb/createclouduser', // 开通云环境
        'get_env_info' => self::WE_CHAT_API_URL.'/tcb/getenvinfo', // 获取云环境信息
        'create_env_and_resource' => self::WE_CHAT_API_URL.'/tcb/createenvandresource', // 创建云环境
        'create_function' => self::WE_CHAT_API_URL.'/tcb/createfunction', // 创建云函数
        'get_upload_signature' => self::WE_CHAT_API_URL.'/tcb/getuploadsignature', // 云上传的签名地址
        'database_collection_add' => self::WE_CHAT_API_URL.'/tcb/databasecollectionadd', // 创建小程序云开发的数据库
        'download_function' => self::WE_CHAT_API_URL.'/tcb/downloadfunction', // 云函数下载地址
        'upload_func_config' => self::WE_CHAT_API_URL.'/tcb/uploadfuncconfig', // 上传云函数配置
        'database_migrate_import' => self::WE_CHAT_API_URL.'/tcb/databasemigrateimport', // 数据库导入
        'database_migrate_query_info' => self::WE_CHAT_API_URL.'/tcb/databasemigratequeryinfo', // 数据库迁移状态查询
        'get_qCloud_token' => self::WE_CHAT_API_URL.'/tcb/getqcloudtoken', // 获取腾讯云API调用凭证
    ];
    static $wxChatCode = [
        "0" => "请求成功", "40001" => "AppSecret错误或者AppSecret不属于小程序或者公众号", "40002" => "不合法的grant_type", "40003" => "不合法的OpenID", "40004" => "不合法的媒体文件类型",
        "40007" => "不合法的media_id", "40008" => "不合法的message_type", "40009" => "不合法的图片大小", "40010" => "不合法的语音大小", "40011" => "不合法的视频大小",
        "40012" => "不合法的缩略图大小", "40013" => "不合法的AppID", "40014" => "不合法的access_token", "40015" => "不合法的菜单类型", "40016" => "不合法的菜单按钮个数",
        "40017" => "不合法的按钮类型", "40018" => "不合法的按钮名称长度", "40019" => "不合法的按钮KEY长度", "40020" => "不合法的url长度", "40023" => "不合法的子菜单按钮个数",
        "40024" => "不合法的子菜单类型", "40025" => "不合法的子菜单按钮名称长度", "40026" => "不合法的子菜单按钮KEY长度", "40027" => "不合法的子菜单按钮url长度",
        "40029" => "不合法或已过期的code", "40030" => "不合法的refresh_token", "40036" => "不合法的template_id长度", "40037" => "不合法的template_id", "40039" => "不合法的url长度",
        "40048" => "不合法的url域名", "40054" => "不合法的子菜单按钮url域名", "40055" => "不合法的菜单按钮url域名", "40066" => "不合法的url", "40101" => "缺少必填参数",
        "40125" => "AppSecret 错误或者 AppSecret 不属于这个小程序", "40164" => "当前IP不是公众号或小程序的IP白名单，请在IP白名单中进行设置", "41001" => "缺失access_token参数",
        "41002" => "缺失appid参数", "41003" => "缺失refresh_token参数", "41004" => "缺失secret参数", "41005" => "缺失二进制媒体文件", "41006" => "缺失media_id参数",
        "41007" => "缺失子菜单数据", "41033" => "小程序不是通过第三方平台创建", "41008" => "缺失code参数", "41009" => "缺失openid参数", "41010" => "缺失url参数",
        "42001" => "access_token超时", "42002" => "refresh_token超时", "42003" => "code超时", "43001" => "需要使用GET方法请求", "43002" => "需要使用POST方法请求",
        "43003" => "需要使用HTTPS", "43004" => "需要订阅关系", "44001" => "空白的二进制数据", "48001" => "小程序未授权", "44002" => "空白的POST数据", "44003" => "空白的news数据",
        "44004" => "空白的内容", "44005" => "空白的列表", "45001" => "二进制文件超过限制", "45002" => "content参数超过限制", "41030" => "所传page页面不存在，或者小程序没有发布",
        "50002" => "用户受限，请检查小程序或者公众号", '61004' => '当前客户端ip未在开放平台白名单', '61023' => '授权已过期,请重新授权', "45003" => "title参数超过限制",
        "45004" => "description参数超过限制", "45005" => "url参数长度超过限制", "45006" => "picurl参数超过限制", "45007" => "播放时间超过限制（语音为60s最大）",
        '61007' => '公众号或者小程序已在公众平台解绑或者权限集不够，不具备调用该接口的权限', "45008" => "article参数超过限制", "45009" => "接口调动频率超过限制",
        "45010" => "建立菜单被限制", "45011" => "频率限制", "45012" => "模板大小超过限制", "45016" => "不能修改默认组", "45017" => "修改组名过长", "45018" => "组数量过多",
        "50001" => "接口未授权", "85015" => "该账号不是小程序账号", '85001' => '微信号不存在或微信号设置为不可搜索', '85002' => '小程序绑定的体验者数量达到上限',
        '85003' => '微信号绑定的小程序体验者达到上限', '85004' => '微信号已经绑定', '85079' => '小程序没有线上版本，不能进行灰度', '85080' => '小程序提交的审核未审核通过',
        '87011' => '现网已经在灰度发布，不能进行版本回退', '87013' => '撤回次数达到上限（每天一次，每个月10次）', "85016" => "域名数量超过限制",
        '87012' => '该版本不能回退，可能的原因：1:无上一个线上版用于回退 2:此版本为已回退版本，不能回退 3:此版本为回退功能上线之前的版本，不能回退',
        "85017" => "没有新增域名，请确认小程序已经添加了域名或该域名是否没有在第三方平台添加", "85018" => "域名没有在第三方平台设置",
        "89019" => "业务域名无更改，无需重复设置", "89020" => "尚未设置小程序业务域名，请先在第三方平台中设置小程序业务域名后在调用本接口", "85058" => "未查询到小程序的提审记录",
        "89021" => "请求保存的域名不是第三方平台中已设置的小程序业务域名或子域名", "89029" => "业务域名数量超过限制", "89231" => "个人小程序不支持调用 setwebviewdomain 接口",
        "-1" => "系统繁忙", "85064" => "找不到模版", "85013" => "无效的自定义配置", "85014" => "无效的模版编号", "85043" => "模版错误", "85044" => "代码包超过大小限制",
        "85045" => "ext_json 有不存在的路径", "85046" => "tabBar 中缺少 path", "85047" => "pages 字段为空", "85048" => "ext_json 解析失败", "80082" => "没有权限使用该插件",
        "80067" => "找不到使用的插件", "80066" => "非法的插件版本", "86000" => "不是由第三方代小程序进行调用", "86001" => "不存在第三方的已经提交的代码", "85006" => "标签格式错误",
        "85007" => "页面路径错误", "85008" => "类目填写错误", "85009" => "已经有正在审核的版本", "85010" => "item_list 有项目为空", "85011" => "标题填写错误", "85012" => "无效的审核 id",
        "61003" => "公众号或者小程序需要重新授权第三方平台", "85023" => "审核列表填写的项目数不在 1-5 以内", "85077" => "小程序类目信息失效（类目中含有官方下架的类目，请重新选择类目）",
        "86002" => "小程序还未设置昵称、头像、简介。请先设置完后再重新提交", "85085" => "近 7 天提交审核的小程序数量过多，请耐心等待审核完毕后再次提交", "85020" => "审核状态未满足发布",
        "85086" => "提交代码审核之前需提前上传代码", "85087" => "小程序已使用 api navigateToMiniProgram，请声明跳转 appid 列表后再次提交", "85019" => "没有审核版本",
        "-1000" => "系统错误	", "85088" => "该APP未开通云开发", "-401001" => "SDK 通用错误：无权限使用 API", "-401002" => "SDK 通用错误：API 传入参数错误", "40097" => "参数错误",
        "-401003" => "SDK 通用错误：API 传入参数类型错误", "-402001" => "SDK 数据库错误：检测到循环引用", "-403001" => "SDK 文件存储错误：上传的文件超出大小上限",
        "-40400" => "SDK 云函数错误：云函数调用失败", "-404011" => "SDK 云函数错误：云函数执行失败", "-501001" => "云端系统错误", "-501002" => "云端响应超时",
        "-501003" => "请求次数超出环境配额", "-501004" => "请求并发数超出环境配额", "-501005" => "环境信息异常", "-501007" => "参数错误", "-501009" => "操作的资源对象非法或不存在",
        "-501015" => "读请求次数配额耗尽", "-501016" => "写请求次数配额耗尽", "-501017" => "磁盘耗尽", "-501018" => "资源不可用或者云环境数已经2个了", "-501019" => "未授权操作",
        "-501020" => "未知参数错误", "-501021" => "操作不支持", "-502001" => "数据库请求失败", "-502002" => "非法的数据库指令", "-502003" => "无权限操作数据库",
        "-502005" => "集合不存在", "-502010" => "操作失败", "-502011" => "操作超时", "-502012" => "插入失败", "-502013" => "创建集合失败", "-502014" => "删除数据失败",
        "-502015" => "查询数据失败", "-503001" => "云资源文件存储错误：云文件请求失败", "-503002" => "云资源文件存储错误：无权限访问云文件", "-504001" => "云函数调用失败",
        "-503003" => "云资源文件存储错误：非法签名", "-504002" => "云函数执行失败", "-601001" => "系统错误", "-601002" => "系统参数错误", "-601003" => "系统网络错误",
        "-604001" => "微信后台云函数错误：回包大小超过 1M", "-604102" => "微信后台云函数错误：调用超时", "-604101" => "微信后台云函数错误：调用系统错误",
        "-605101" => "微信后台 HTTP API 错误：查询语句解析失败",
    ]; // 微信返回的消息
}
